<?php

namespace App\Library\Common;

class JwtTool
{
    /**
     * 解析jwt，获取payload
     * @param $jwtToken
     * @return array
     */
    public static function getJwtPayload($jwtToken): array
    {
        $tokenParts = explode('.', $jwtToken);

        if (count($tokenParts) === 3) {
            $payloadBase64 = $tokenParts[1];
            $payload       = base64_decode($payloadBase64);
            return (array)json_decode($payload, true);
        } else {

            // 处理无效的 JWT
            return [];
        }
    }
}
